<?php

namespace Applications\Backoffice\Modules\Users;

class UsersController extends \Library\BackController {

    public function executeIndex(\Library\HTTPRequest $request) {
        $this->page->addVar('title', 'Users');
        if($request->getExists('submenu')){
            $this->page->addVar('submenu', $request->getData('submenu'));
            $manager = $this->managers->getManagerOf('Users');
            $listeGroups = $manager->getListGroup();
            foreach ($listeGroups as $Group) {
                //rien pour le moment
            }
            // On ajoute la variable $listeGroups à la vue
            $this->page->addVar('listeGroups', $listeGroups);
        } else {
        // On récupère le manager des Users
        $manager = $this->managers->getManagerOf('Users');
        $listeUsers = $manager->getList();
        foreach ($listeUsers as $User) {
            if($User['active_account'] == 1){
                $User['active_account'] = 'Oui';
            }
            else{
                $User['active_account'] = 'Non';
            }
        }
        // On ajoute la variable $listeUsers à la vue
        $this->page->addVar('listeUsers', $listeUsers);
        }
    }
    
    public function executeDelete(\Library\HTTPRequest $request) {
        $manager = $this->managers->getManagerOf('Users');
        if($request->getExists('user')){
            $user = $request->getData('user');
            $manager->deleteUser($user);
        }
        $this->app->httpResponse()->redirect('users.html');
    }
    
    public function executeAddGroup(\Library\HTTPRequest $request) {
        $manager = $this->managers->getManagerOf('Users');
        if($request->getExists('submenu')){
            
        }
        
    }

}
?>
